home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / addhost / RCS / addhost,v < prev    next >
Encoding:
Text File  |  1991-07-15  |  33.6 KB  |  1,701 lines

  1. head     1.14;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    jhh:1.14; strict;
  6. comment  @# @;
  7.  
  8.  
  9. 1.14
  10. date     90.11.06.16.22.33;  author jhh;  state Exp;
  11. branches ;
  12. next     1.13;
  13.  
  14. 1.13
  15. date     90.09.13.12.01.54;  author jhh;  state Exp;
  16. branches ;
  17. next     1.12;
  18.  
  19. 1.12
  20. date     90.06.28.15.16.50;  author jhh;  state Exp;
  21. branches ;
  22. next     1.11;
  23.  
  24. 1.11
  25. date     90.04.03.11.48.47;  author jhh;  state Exp;
  26. branches ;
  27. next     1.10;
  28.  
  29. 1.10
  30. date     90.03.07.11.06.42;  author jhh;  state Exp;
  31. branches ;
  32. next     1.9;
  33.  
  34. 1.9
  35. date     90.02.14.22.36.13;  author jhh;  state Exp;
  36. branches ;
  37. next     1.8;
  38.  
  39. 1.8
  40. date     90.02.12.21.12.13;  author jhh;  state Exp;
  41. branches ;
  42. next     1.7;
  43.  
  44. 1.7
  45. date     90.02.12.20.48.35;  author jhh;  state Exp;
  46. branches ;
  47. next     1.6;
  48.  
  49. 1.6
  50. date     90.01.24.16.07.49;  author jhh;  state Exp;
  51. branches ;
  52. next     1.5;
  53.  
  54. 1.5
  55. date     90.01.24.15.11.28;  author jhh;  state Exp;
  56. branches ;
  57. next     1.4;
  58.  
  59. 1.4
  60. date     90.01.18.17.55.18;  author jhh;  state Exp;
  61. branches ;
  62. next     1.3;
  63.  
  64. 1.3
  65. date     90.01.18.17.42.38;  author jhh;  state Exp;
  66. branches ;
  67. next     1.2;
  68.  
  69. 1.2
  70. date     90.01.17.17.46.40;  author jhh;  state Exp;
  71. branches ;
  72. next     1.1;
  73.  
  74. 1.1
  75. date     90.01.16.13.20.52;  author jhh;  state Exp;
  76. branches ;
  77. next     ;
  78.  
  79.  
  80. desc
  81. @original version
  82. @
  83.  
  84.  
  85. 1.14
  86. log
  87. @added ds5000 support
  88. @
  89. text
  90. @#!/bin/csh -f
  91. #
  92. # Script for adding a new host to a Sprite system.  It creates directories,
  93. # makes links, and edits files.
  94. #
  95. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.13 90/09/13 12:01:54 jhh Exp Locker: jhh $ SPRITE (Berkeley)
  96. #
  97. # Copyright 1989 Regents of the University of California
  98. # Permission to use, copy, modify, and distribute this
  99. # software and its documentation for any purpose and without
  100. # fee is hereby granted, provided that the above copyright
  101. # notice appear in all copies.  The University of California
  102. # makes no representations about the suitability of this
  103. # software for any purpose.  It is provided "as is" without
  104. # express or implied warranty.
  105. #
  106.  
  107. onintr cleanup
  108.  
  109. #set debugFlag
  110. set awk = 'nawk'
  111. set netType="ether"
  112. set root="/"
  113. set domain = "";
  114. set domain = `$awk '/^[0-9]+/ {print substr($6, index($6,".")+1);exit;}' $root/etc/spritehosts`
  115. set swapDir = "/swap"
  116. set owner = ""
  117. set location = ""
  118. set fullType = ""
  119.  
  120.  
  121. set tmpfile=/tmp/addhost.$$
  122. set tmpfile2=/tmp/addhost2.$$
  123. set spriteID = 0
  124.  
  125. if ($#argv > 0) then
  126.     while ($#argv)
  127.     switch ($1)
  128.         case "-r":
  129.         shift
  130.         if ($#argv == 0) then
  131.             echo "-r option requires an argument"
  132.             goto usage
  133.         else
  134.             set root = $1
  135.             shift
  136.         endif
  137.         breaksw
  138.         case "-i":
  139.         shift
  140.         if ($#argv == 0) then
  141.             echo "-i option requires an argument"
  142.             goto usage
  143.         else
  144.             set internet = $1
  145.             shift
  146.         endif
  147.         breaksw
  148.         case "-a":
  149.         shift
  150.         if ($#argv == 0) then
  151.             echo "-a option requires an argument"
  152.         else
  153.             set address = $1
  154.             shift
  155.         endif
  156.         breaksw
  157.         case "-n"
  158.         shift
  159.         if ($#argv == 0) then
  160.             echo "-n option requires an argument"
  161.         else
  162.             set name = $1
  163.             shift
  164.         endif
  165.         breaksw
  166.         case "-I"
  167.         shift
  168.         if ($#argv == 0) then
  169.             echo "-I option requires an argument"
  170.         else
  171.             set spriteID = $1
  172.             shift
  173.         endif
  174.         breaksw
  175.         case "-d"
  176.         shift
  177.         if ($#argv == 0) then
  178.             echo "-d option requires an argument"
  179.         else
  180.             set domain = $1
  181.             shift
  182.         endif
  183.         breaksw
  184.         case "-m"
  185.         shift
  186.         if ($#argv == 0) then
  187.             echo "-m option requires an argument"
  188.         else
  189.             set machineType = $1
  190.             shift
  191.         endif
  192.         breaksw
  193.         case "-t"
  194.         shift
  195.         if ($#argv == 0) then
  196.             echo "-t option requires an argument"
  197.         else
  198.             set netType = $1
  199.             shift
  200.         endif
  201.         breaksw
  202.         case "-s"
  203.         shift
  204.         if ($#argv == 0) then
  205.             echo "-s option requires an argument"
  206.         else
  207.             set swapDir = $1
  208.             shift
  209.         endif
  210.         breaksw
  211.         case "-R"
  212.         shift
  213.         set replace
  214.         breaksw
  215.         case "-o"
  216.         shift
  217.         if ($#argv == 0) then
  218.             echo "-o option requires an argument"
  219.         else
  220.             set owner = "$1"
  221.             shift
  222.         endif
  223.         breaksw
  224.         case "-l"
  225.         shift
  226.         if ($#argv == 0) then
  227.             echo "-l option requires an argument"
  228.         else
  229.             set location = "$1"
  230.             shift
  231.         endif
  232.         breaksw
  233.         case "-T"
  234.         shift
  235.         if ($#argv == 0) then
  236.             echo "-T option requires an argument"
  237.         else
  238.             set fullType = $1
  239.             shift
  240.         endif
  241.         breaksw
  242.         case "-h"
  243.         case "-help"
  244.         case "-?"
  245.         shift
  246.         goto usage
  247.         breaksw
  248.         default:
  249.         echo "Invalid option" $1 "to $0"
  250.         shift
  251.         goto usage
  252.         breaksw
  253.     endsw
  254.     end
  255.     
  256.     if (! $?internet) then
  257.     echo "-i option is required"
  258.     goto usage
  259.     endif
  260.     
  261.     if (! $?address) then
  262.     echo "-a option is required"
  263.     goto usage
  264.     endif
  265.     
  266.     if (! $?name) then
  267.     echo "-n option is required"
  268.     goto usage
  269.     endif
  270.     
  271.     if (! $?machineType) then
  272.     echo "-m option is required"
  273.     goto usage
  274.     endif
  275.     
  276.     if (! $?swapDir) then
  277.     echo "-s option is required"
  278.     goto usage
  279.     endif
  280.     if ($domain == "") then
  281.     set domain = 
  282.         `$awk '/^[0-9]+/ {print substr($6, index($6,".")+1);exit;}' 
  283.         $root/etc/spritehosts`
  284.     endif
  285.     if ($domain == "") then
  286.     echo "Can't determine domain from $root/etc/spritehosts. Use -d flag"
  287.     goto usage
  288.     endif
  289.  
  290.     if (! -d "$root") then
  291.     echo "The directory $root does not exist"
  292.     goto usage
  293.     endif
  294.  
  295.     if ($?SPRITE_OS) then
  296.     rcsinfo $root/etc/RCS |& grep spritehosts > /dev/null
  297.     if ($status == 0) then
  298.         echo "Please check in $root/etc/spritehosts"
  299.         exit 1;
  300.     endif
  301.     rcsinfo $root/etc/RCS |& grep hosts.equiv > /dev/null
  302.     if ($status == 0) then
  303.         echo "Please check in $root/etc/hosts.equiv"
  304.         exit 1;
  305.     endif
  306.     rcsinfo $root/sprite/admin/RCS |& grep hosts > /dev/null
  307.     if ($status == 0) then
  308.         echo "Please check in $root/sprite/admin/hosts"
  309.         exit 1;
  310.     endif
  311.     rcsinfo $root/etc/RCS |& grep hosts > /dev/null
  312.     if ($status == 0) then
  313.         echo "Please check in $root/etc/hosts"
  314.         exit 1;
  315.     endif
  316.  
  317.     endif
  318. else
  319.     set interactive
  320.     set machineType = ""
  321.     set name = ""
  322.     set address = ""
  323.     set internet = ""
  324.     set swapDir = "/swap"
  325.  
  326. startQuestions:
  327.     echo ""
  328.     echo "Please answer the following questions."
  329.     echo "Default answers are surrounded by ()'s."
  330.     echo "Multiple choices are surrounded by []'s"
  331.     echo ""
  332.     echo -n "Name of Sprite filesystem root ($root): "
  333.     set answer = $<
  334.     if ("$answer" != "") set root = "$answer"
  335.  
  336.     if (! -d $root/. ) then
  337.     echo "The directory $root does not exist"
  338.     goto startQuestions
  339.     endif
  340.  
  341.     if ($?SPRITE_OS) then
  342.     rcsinfo $root/etc/RCS |& grep spritehosts > /dev/null
  343.     if ($status == 0) then
  344.         echo "Please check in $root/etc/spritehosts"
  345.         exit 1;
  346.     endif
  347.     rcsinfo $root/etc/RCS |& grep hosts.equiv > /dev/null
  348.     if ($status == 0) then
  349.         echo "Please check in $root/etc/hosts.equiv"
  350.         exit 1;
  351.     endif
  352.     rcsinfo $root/sprite/admin/RCS |& grep hosts > /dev/null
  353.     if ($status == 0) then
  354.         echo "Please check in $root/sprite/admin/hosts"
  355.         exit 1;
  356.     endif
  357.     rcsinfo $root/etc/RCS |& grep hosts > /dev/null
  358.     if ($status == 0) then
  359.         echo "Please check in $root/etc/hosts"
  360.         exit 1;
  361.     endif
  362.     endif
  363.  
  364.     echo -n "Machine name ($name): "
  365.     set answer = $<
  366.     if ("$answer" != "") set name = "$answer"
  367.  
  368.     echo -n "Machine type [sun3, sun4, sun4c, ds3100, symm, ds5000] "
  369.     echo -n "($machineType): "
  370.     set answer = $<
  371.     if ("$answer" != "") set machineType = "$answer"
  372.  
  373.     echo -n "Type of local network [ether, inet] ($netType): "
  374.     set answer = $<
  375.     if ("$answer" != "") set netType = "$answer"
  376.  
  377.     echo -n "Local network address, eg 8:0:28:1:0f:EC ($address): "
  378.     set answer = $<
  379.     if ("$answer" != "") set address = "$answer"
  380.  
  381.     echo -n "Internet address, eg 128.32.150.11 ($internet): "
  382.     set answer = $<
  383.     if ("$answer" != "") set internet = "$answer"
  384.  
  385.     echo -n "Internet domain ($domain): "
  386.     set answer = $<
  387.     if ("$answer" != "") set domain = "$answer"
  388.  
  389.     echo -n "Swap directory ($swapDir): "
  390.     set answer = $<
  391.     if ("$answer" != "") set swapDir = "$answer"
  392.  
  393.     echo -n "Sprite id, default is to assign a new one: "
  394.     set answer = $<
  395.     if ("$answer" != "") set spriteID = "$answer"
  396.  
  397.     echo -n "Owner or primary user of machine ($owner): "
  398.     set answer = $<
  399.     if ("$answer" != "") set owner = "$answer"
  400.  
  401.     echo -n "Location of machine ($location): "
  402.     set answer = $<
  403.     if ("$answer" != "") set location = "$answer"
  404.  
  405.     echo -n "Description of machine, ex. sun3/75, sun4/280 ($fullType): "
  406.     set answer = $<
  407.     if ("$answer" != "") set fullType = "$answer"
  408.  
  409.  
  410.     echo ""
  411.     if ($name == "") then
  412.     echo "You must specify a name for the machine"
  413.     goto startQuestions
  414.     endif
  415.     if ($address == "") then
  416.     echo "You must specify a local net address"
  417.     goto startQuestions
  418.     endif
  419.     if ($internet == "") then
  420.     echo "You must specify an internet address"
  421.     goto startQuestions
  422.     endif
  423.     if ($domain == "") then
  424.     set domain = 
  425.         `$awk '/^[0-9]+/ {print substr($6, index($6,".")+1);exit;}' 
  426.         $root/etc/spritehosts`
  427.     endif
  428.     if ($domain == "") then
  429.     echo "You must specify a domain"
  430.     goto startQuestions
  431.     endif
  432. endif
  433. if ($?debugFlag) then
  434.     set debug = "echo"
  435. else
  436.     set debug = ""
  437. endif
  438.  
  439. if ("$root" == "/") set root = ""
  440.  
  441. #
  442. # Check that machine type is valid
  443. #
  444. switch ($machineType) 
  445.     case "sun3"
  446.     case "sun4"
  447.     case "ds3100"
  448.     case "symm"
  449.     case "ds5000"
  450.     set spriteHostType = $machineType
  451.     breaksw
  452.     case "sun4c"
  453.     set spriteHostType = "sun4"
  454.     breaksw
  455.     default
  456.     echo -n "Machine type must be one of "
  457.     echo "[sun3, sun4, sun4c, ds3100, symm, ds5000]"
  458.     if ($?interactive) then
  459.         goto startQuestions
  460.     else
  461.         goto usage
  462.     endif
  463. endsw
  464.  
  465. #
  466. # Check that the network type is valid
  467. #
  468. switch ($netType)
  469.     case "ether"
  470.     case "inet"
  471.     breaksw
  472.     default
  473.     echo "Network type must be one of [ether, inet]"
  474.     if ($?interactive) then
  475.         goto startQuestions
  476.     else
  477.         goto usage
  478.     endif
  479. endsw
  480.  
  481. set fullName=$name.$domain
  482. if ($fullType == "") then
  483.     set fullType = $machineType
  484. endif
  485.  
  486. echo "Name:             $name"
  487. echo "Full name:        $fullName"
  488. echo "Machine type:        $machineType"
  489. echo "Local net address:    $address"
  490. echo "Local net type:        $netType"
  491. echo "Internet address:     $internet"
  492. if ($spriteID != 0) then
  493.     echo "Sprite ID:        $spriteID"
  494. endif
  495. echo "Swap directory:        $swapDir"
  496. echo "Owner:            $owner"
  497. echo "Location:            $location"
  498. echo "Machine description:    $fullType"
  499.  
  500. if ($?interactive) then
  501.     echo -n "Is the above information correct? (y) "
  502.     set answer = $<
  503.     if (("$answer" != "") && ("$answer" !~ [yY]*)) goto startQuestions
  504. endif
  505.  
  506. if ("$owner" == "") set owner = "JOE NOBODY"
  507. if ("$location" == "") set location = "UNKNOWN"
  508.  
  509. cat << AWK_EOF > $tmpfile
  510. BEGIN {
  511.     id = "$spriteID";
  512.     status = 0;
  513. }
  514.  
  515. \$7 ~ /^$name\$/ {
  516.     printf("\nLine %d of %s: name %s already used\n", NR,  
  517.     FILENAME, "$name");
  518.     print ">>> " \$0;
  519.     if (status < 2) {
  520.     status = 2;
  521.     }
  522. }
  523. \$1 == "$spriteID" {
  524.     printf("\nLine %d of %s: id %d already used\n", NR, FILENAME, id);
  525.     print ">>> " \$0;
  526.     print NR \$5 > "$tmpfile2";
  527.     if (status < 2) {
  528.     status = 2;
  529.     }
  530. }
  531. /^#[ \t]*[0-9]+/ {
  532.     n = split(\$1, w, "#");
  533.     if (id == w[n]) {
  534.         printf("\nLine %d of %s: id %d used in a commented-out line", NR,  
  535.         FILENAME,id);
  536.         print ">>> " \$0;
  537.         if (status < 1) {
  538.         status = 1;
  539.         }
  540.         print;
  541.     }
  542. }
  543. \$3 ~ /^$address\$/ {
  544.     printf("\nLine %d of %s: address %s already used\n", NR,
  545.     FILENAME,"$address");
  546.     print ">>> " \$0;
  547.     if (status < 2) {
  548.     status = 2;
  549.     }
  550. }
  551. \$4 ~ /^$internet\$/ {
  552.     printf("\nLine %d of %s: internet address %s already used\n", NR,  
  553.     FILENAME,$internet);
  554.     print ">>> " \$0;
  555.     if (status < 2) {
  556.     status = 2;
  557.     }
  558.  
  559. }
  560. END {
  561.     exit(status);
  562. }
  563. AWK_EOF
  564.  
  565. $awk -f $tmpfile $root/etc/spritehosts
  566. switch ($status) 
  567.     case '0' 
  568.     case '1' 
  569.     breaksw
  570.     case '2'  
  571.     if ($?interactive) then
  572.         set response = "n";
  573.         echo -n "Do you want to add the host anyway? (n) "
  574.         set answer = $<
  575.         if ("$answer" != "") set response = "$answer"
  576.         if ($response !~ [yY]*) then
  577.         goto startQuestions
  578.         endif
  579.     else
  580.         if (! $?replace) then
  581.         echo "Host $name is already in spritehosts."
  582.         echo "Use the -R flag"
  583.         exit 1
  584.         endif
  585.     endif
  586.     breaksw
  587. endsw
  588. # The following awk script is used to add the new machine to /etc/spritehosts.
  589. # If the spriteID is 0 then a new spriteID is assigned that is one
  590. # greater than the largest found in the file.  The script is also smart
  591. # enough to know that all inet address must follow ethernet addresses.
  592. # Thats what the 'save' array is used for.
  593. #
  594. cat << AWK_EOF > $tmpfile
  595. BEGIN {
  596.     id = "$spriteID";
  597.     netType = "$netType";
  598.     addr = "$address";
  599.     inet = "$internet";
  600.     type = "$spriteHostType";
  601.     fullName = "$fullName";
  602.     name = "$name";
  603.     if (id != 0) {
  604.     assignID=0;
  605.     } else {
  606.     assignID=1;
  607.     }
  608.     line = 1;
  609.     biggestid = 0;
  610.     inetStart = 0;
  611. }
  612. {
  613.     currentid = 0;
  614. }
  615. /^[^0-9]/ {
  616.     if (\$1 ~ /^#[ \t]*[0-9]+/) {
  617.     n = split(\$1, w, "#");
  618.     currentid = w[n];
  619.     if (inetStart == 0) {
  620.         etherEnd = line;
  621.     }
  622.     }
  623. }
  624. /^[0-9]/ {
  625.     currentid = \$1;
  626.     if (\$7 == name) {
  627.     next;
  628.     }
  629. }
  630. \$2 == "inet" {
  631.     inetStart = line;
  632. }
  633. \$2 == "ether" {
  634.     etherEnd = line;
  635. }
  636. {
  637.     save[line] = \$0;
  638.     if (currentid != 0) {
  639.     saveid[line] = currentid;
  640.     if (currentid  + 0 > biggestid) {
  641.         biggestid = currentid;
  642.     }
  643.     }
  644.     line++;
  645. }
  646. END {
  647.     if (assignID) {
  648.     id = biggestid + 1;
  649.     }
  650.     print1 = 0;
  651.     print2 = 0;
  652.     for(i = 1; i < line ; i++) {
  653.     if (!print1) {
  654.         if (saveid[i] + 0 > id || i + 0 > etherEnd) {
  655.         if (netType == "ether") {
  656.             printf("%d %s %s %s %s %s %s\n", 
  657.             id, netType, addr, inet, type, fullName, name);
  658.         } else {
  659.             printf("#%d is at bottom of file\n", id);
  660.         }
  661.         print1 = 1;
  662.         }
  663.     }
  664.     if (!print2) {
  665.         if (saveid[i] + 0 > id && i + 0 > inetStart && netType == "inet"){
  666.         printf("%d %s %s %s %s %s %s\n", 
  667.             id, netType, addr, inet, type, fullName, name);
  668.         print2 = 1;
  669.         }
  670.     }
  671.     print save[i];
  672.     }
  673.     if (!print2 && netType == "inet") {
  674.     printf("%d %s %s %s %s %s %s\n", 
  675.         id, netType, addr, inet, type, fullName, name);
  676.     }
  677.     print id > "$tmpfile2";
  678. }
  679. AWK_EOF
  680.  
  681. echo "Adding to $root/etc/spritehosts"
  682. pushd $root/etc > /dev/null
  683. if ($?SPRITE_OS) then
  684.     $debug co -l spritehosts
  685.     if ($status) then
  686.     echo "co -l failed ($status)"
  687.     exit 1
  688.     endif
  689. endif
  690. $awk -f $tmpfile spritehosts > spritehosts.new 
  691. if ($status) then
  692.     echo "Awk of spritehosts failed ($status)
  693.     exit 1
  694. endif
  695. $debug mv spritehosts.new spritehosts
  696. if ($status) then
  697.     echo "Move of spritehosts.new to spritehosts failed ($status)
  698. endif
  699. if ($?SPRITE_OS) then
  700.     $debug rcsdiff spritehosts > /dev/null
  701.     if ($status) then
  702.     $debug ci -u -m"$name added by addhost" spritehosts
  703.     if ($status) then
  704.         echo "ci -u failed ($status)"
  705.         exit 1
  706.     endif
  707.     else
  708.     rcs -u spritehosts
  709.     chmod -w spritehosts
  710.     endif
  711. endif
  712. popd > /dev/null
  713. if ($spriteID == 0) then
  714.     set spriteID = `cat $tmpfile2`
  715.     echo "Sprite ID:        $spriteID"
  716. endif
  717.  
  718. #
  719. # Add the machine to /etc/hosts.equiv.
  720. #
  721. grep $fullName $root/etc/hosts.equiv > /dev/null
  722. if ($status == 1) then
  723.     echo "Adding to $root/etc/hosts.equiv"
  724.     pushd $root/etc > /dev/null
  725.     if ($?SPRITE_OS) then
  726.     $debug co -l hosts.equiv
  727.     if ($status) then
  728.         echo "co -l failed ($status)"
  729.         exit 1
  730.     endif
  731.     endif
  732.     echo "$fullName" > $tmpfile
  733.     cat $tmpfile hosts.equiv | sort > hosts.equiv.new
  734.     $debug mv hosts.equiv.new hosts.equiv
  735.     if ($?SPRITE_OS) then
  736.     $debug ci -u -m"$name added by addhost" hosts.equiv
  737.     if ($status) then
  738.         echo "ci -u failed ($status)"
  739.         exit 1
  740.     endif
  741.     endif
  742.     popd > /dev/null
  743. else
  744.     echo "$fullName is already in $root/etc/hosts.equiv"
  745. endif
  746. #
  747. # Adding to /etc/hosts
  748. #
  749. grep $fullName $root/etc/hosts > /dev/null
  750. if ($status == 1) then
  751.     echo "Adding to $root/etc/hosts"
  752.     pushd $root/etc > /dev/null
  753.     if ($?SPRITE_OS) then
  754.     $debug co -l hosts
  755.     if ($status) then
  756.         echo "co -l failed ($status)"
  757.         exit 1
  758.     endif
  759.     endif
  760.     echo "$internet $fullName $name" > $tmpfile
  761.     cat $tmpfile hosts | sort > hosts.new
  762.     $debug mv hosts.new hosts
  763.     if ($?SPRITE_OS) then
  764.     $debug ci -u -m"$name added by addhost" hosts
  765.     if ($status) then
  766.         echo "ci -u failed ($status)"
  767.         exit 1
  768.     endif
  769.     endif
  770.     popd > /dev/null
  771. else
  772.     echo "$fullName is already in $root/etc/hosts"
  773. endif
  774.  
  775.  
  776. #
  777. # Add the machine to /sprite/admin/hosts
  778. #
  779. echo "Adding to $root/sprite/admin/hosts"
  780. pushd $root/sprite/admin > /dev/null
  781. if ($?SPRITE_OS) then
  782.     $debug co -l hosts
  783.     if ($status) then
  784.     echo "co -l failed ($status)"
  785.     exit 1
  786.     endif
  787. endif
  788. cat << AWK_EOF > $tmpfile
  789. BEGIN {
  790.     printf("%-15s%-15s%-15s %s\n","$name","$fullType","$location","$owner") | "sort";
  791.     phase = 0;
  792. }
  793. /^$name/ {
  794.     next;
  795. }
  796. /^[^#]/ {
  797.     phase = 1;
  798.     print | "sort";
  799.     next;
  800. }
  801. if (phase == 0) {
  802.     print >> "/tmp/addhost.out1.$$";
  803.   } else {
  804.     print >> "/tmp/addhost.out3.$$";
  805.   }
  806. }
  807.  
  808. AWK_EOF
  809. $awk -f $tmpfile hosts > /tmp/addhost.out2.$$
  810. if (-e /tmp/addhost.out3.$$) then
  811.     cat /tmp/addhost.out1.$$ /tmp/addhost.out2.$$ /tmp/addhost.out3.$$ > hosts.new
  812. else
  813.     cat /tmp/addhost.out1.$$ /tmp/addhost.out2.$$  > hosts.new
  814. endif
  815. $debug mv hosts.new hosts
  816. if ($?SPRITE_OS) then
  817.     $debug rcsdiff hosts > /dev/null
  818.     if ($status) then
  819.     $debug ci -u -m"$name added by addhost" hosts
  820.     if ($status) then
  821.         echo "ci -u failed ($status)"
  822.         exit 1
  823.     endif
  824.     else
  825.     rcs -u hosts
  826.     chmod -w hosts
  827.     endif
  828. endif
  829. popd > /dev/null
  830.  
  831. #
  832. # Now we create /hosts/foo, /hosts/foo.Berkeley.EDU, and /hosts/foo/dev/syslog.
  833. #
  834. if (! -e $root/hosts/$name.$domain) then
  835.     echo "Creating $root/hosts/$name.$domain"
  836.     $debug mkdir $root/hosts/$name.$domain
  837.     if ($status) then
  838.     echo "mkdir failed ($status)"
  839.     exit 1
  840.     endif
  841.     $debug chmod 777 $root/hosts/$name.$domain
  842.     if ($status) then
  843.     echo "chmod failed ($status)"
  844.     exit 1
  845.     endif
  846. endif
  847.  
  848. echo "Creating symbolic link $root/hosts/$name -> $root/hosts/$name.$domain"
  849. $debug rm -f $root/hosts/$name
  850. $debug ln -s $root/hosts/$name.$domain $root/hosts/$name
  851. if ($status) then
  852.     echo "ln -s failed ($status)"
  853.     exit 1
  854. endif
  855.  
  856. if (! -e $root/hosts/$name/dev) then
  857.     echo "Creating $root/hosts/$name/dev"
  858.     $debug mkdir $root/hosts/$name/dev
  859.     if ($status) then
  860.     echo "mkdir failed ($status)"
  861.     exit 1
  862.     endif
  863.     $debug chmod 777 $root/hosts/$name/dev
  864.     if ($status) then
  865.     echo "chmod failed ($status)"
  866.     exit 1
  867.     endif
  868. endif
  869.  
  870. $debug rm -f $root/hosts/$name/dev/syslog
  871. echo "Creating $root/hosts/$name/dev/syslog"
  872. if ($?SPRITE_OS) then
  873.     $debug fsmakedev -s $spriteID -d 1 -u 0 $root/hosts/$name/dev/syslog
  874.     if ($status) then
  875.     echo "fsmakedev failed ($status)"
  876.     exit 1
  877.     endif
  878. else
  879.     echo "# This file was created by \"addhost\"." > $tmpfile
  880.     echo "# \"fsmake\" uses it to create Sprite devices." >> $tmpfile
  881.     echo "# Format is: ServerID  Type Unit" >> $tmpfile
  882.     echo "# This particular file is for a syslog device." >> $tmpfile
  883.     echo "$spriteID 1 0" >> $tmpfile
  884.     $debug cp $tmpfile $root/hosts/$name/dev/syslog.SPRITE_DEV
  885. endif
  886.  
  887. #
  888. # Some machine types need other stuff in their dev directories.
  889. #
  890. switch ($machineType)
  891.     case "sun3"
  892.     case "sun4"
  893.     case "sun4c"
  894.     case "ds3100"
  895.     case "symm"
  896.     case "ds5000"
  897.     rm -f $root/hosts/$name/dev/serialB
  898.     echo "ing $root/hosts/$name/dev/serialB"
  899.     if ($?SPRITE_OS) then
  900.         $debug fsmakedev -s $spriteID -d 0 -u 2 \
  901.         $root/hosts/$name/dev/serialB
  902.         if ($status) then
  903.         echo "fsmakedev failed ($status)"
  904.         exit 1
  905.         endif
  906.     else
  907.         echo "# This file was created by \"addhost\"." > $tmpfile
  908.         echo "# \"fsmake\" uses it to create Sprite devices." >> $tmpfile
  909.         echo "# Format is: ServerID  Type Unit" >> $tmpfile
  910.         echo "# This particular file is for a syslog device." >> $tmpfile
  911.         echo "$spriteID 0 2" >> $tmpfile
  912.         $debug cp $tmpfile $root/hosts/$name/dev/serialB.SPRITE_DEV
  913.     endif
  914. endsw
  915.  
  916.  
  917. #
  918. # Now create a link in /sprite/boot, if needed.  Some of the machine
  919. # types need this for tftp to work.  The link name is the hex value
  920. # of the internet address, and points to the net boot program for the
  921. # machine type.  The following awk script converts a.b.c.d internet
  922. # address format into the hex string.
  923. #
  924. cat << AWK_EOF > $tmpfile
  925. BEGIN {
  926.     FS = ".";
  927. }
  928. {
  929.     printf("%02x%02x%02x%02x", \$1, \$2, \$3, \$4);
  930. }
  931. AWK_EOF
  932.  
  933. set hexInet = `echo $internet | $awk -f $tmpfile`
  934. echo "Hex internet address is $hexInet"
  935. pushd $root/sprite/boot
  936. $debug rm -f $hexInet*
  937.  
  938. switch ($machineType) 
  939.     case "sun3" 
  940.     echo "Making link in $root/sprite/boot"
  941.     $debug ln -s sun3.md/netBoot $hexInet
  942.     if ($status) then
  943.         echo "ln -s failed ($status)"
  944.         exit 1
  945.     endif
  946.     breaksw
  947.     case "sun4"
  948.     echo "Making link in $root/sprite/boot"
  949.     $debug ln -s sun4.md/netBoot $hexInet.SUN4
  950.     if ($status) then
  951.         echo "ln -s failed ($status)"
  952.         exit 1
  953.     endif
  954.     breaksw
  955.     case "sun4c"
  956.     echo "Making link in $root/sprite/boot"
  957.     $debug ln -s sun4c.md/netBoot $hexInet.SUN4C
  958.     if ($status) then
  959.         echo "ln -s failed ($status)"
  960.         exit 1
  961.     endif
  962.     breaksw
  963. endsw
  964.  
  965. popd
  966. #
  967. # Create the swap directory
  968. #
  969. echo "Creating swap directory $swapDir/$spriteID"
  970. if (! -d $swapDir/$spriteID) then
  971.     rm -f $swapDir/$spriteID
  972.     $debug mkdir $swapDir/$spriteID
  973.     if ($status) then
  974.     echo "mkdir failed ($status)"
  975.     exit 1
  976.     endif
  977. endif
  978. if ($swapDir != "/swap") then
  979.     echo "Linking /swap/$spriteID -> $swapDir/$spriteID"
  980.     $debug ln -s $swapDir/$spriteID /swap/$spriteID
  981. endif
  982.  
  983. echo 
  984. echo "Do the following:"
  985. echo "   Run 'netroute -f /etc/spritehosts' on all fileservers."
  986. echo "   Add the machine name to /etc/hosts.equiv on ginger."
  987. echo "   If the machine has a color frame buffer then edit Xsprite."
  988. echo "Things you may want to do:"
  989. echo "   Set up tftp booting from ginger"
  990. echo "Read /sprite/admin/howto/addNewHost for detailed instructions"
  991.  
  992. cleanup:
  993.     #rm -f /tmp/addhost*$$
  994.     exit
  995.  
  996. usage:
  997.     echo "Usage: $0 "
  998.     echo "    -n hostName "
  999.     echo "    -i internetAddress "
  1000.     echo "    -a netAddress (ethernet address) "
  1001.     echo "    -m machineType "
  1002.     echo "    -s swapDirectory "
  1003.     echo "    [-d domainName] "
  1004.     echo "    [-r rootDirectory] "
  1005.     echo "    [-I spriteID] "
  1006.     echo "    [-t netType (ethernet)] "
  1007.     echo "    [-R] "
  1008.     echo "    [-o ownerName] "
  1009.     echo "    [-l machineLocation] "
  1010.     echo "    [-T machineDescription] "
  1011.     echo " Ex: $0 -n lust -i 128.32.150.11 -a 8:0:28:1:0f:EC -m spur -s /swap1"
  1012.     exit
  1013.  
  1014. @
  1015.  
  1016.  
  1017. 1.13
  1018. log
  1019. @added symmetry, fixed bug in creating links in /sprite/boot
  1020. @
  1021. text
  1022. @d6 1
  1023. a6 1
  1024. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.12 90/06/28 15:16:50 jhh Exp $ SPRITE (Berkeley)
  1025. d279 2
  1026. a280 1
  1027.     echo -n "Machine type [sun3, sun4, sun4c, ds3100, symm] ($machineType): "
  1028. d360 1
  1029. d367 2
  1030. a368 1
  1031.     echo "Machine type must be one of [sun3, sun4, sun4c, ds3100, symm]"
  1032. d809 1
  1033. @
  1034.  
  1035.  
  1036. 1.12
  1037. log
  1038. @creates the "placeholder" files for Sprite devices when run on unix
  1039. @
  1040. text
  1041. @d6 1
  1042. a6 1
  1043. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.11 90/04/03 11:48:47 jhh Exp $ SPRITE (Berkeley)
  1044. d279 1
  1045. a279 1
  1046.     echo -n "Machine type [sun3, sun4, sun4c, ds3100] ($machineType): "
  1047. d358 1
  1048. d365 1
  1049. a365 1
  1050.     echo "Machine type must be one of [sun3, sun4, sun4c, ds3100]"
  1051. d805 1
  1052. d838 1
  1053. a838 1
  1054.     printf("%x%x%x%x", \$1, \$2, \$3, \$4);
  1055. @
  1056.  
  1057.  
  1058. 1.11
  1059. log
  1060. @fixed typo
  1061. @
  1062. text
  1063. @d6 1
  1064. a6 1
  1065. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.10 90/03/07 11:06:42 jhh Exp $ SPRITE (Berkeley)
  1066. d788 6
  1067. a793 1
  1068.     echo "create syslog"
  1069. d803 1
  1070. d814 6
  1071. a819 1
  1072.         echo "create serialB"
  1073. @
  1074.  
  1075.  
  1076. 1.10
  1077. log
  1078. @adds to /etc/hosts, fixed a few bugs
  1079. @
  1080. text
  1081. @d6 1
  1082. a6 1
  1083. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.9 90/02/14 22:36:13 jhh Exp Locker: jhh $ SPRITE (Berkeley)
  1084. a885 1
  1085. echo "   
  1086. @
  1087.  
  1088.  
  1089. 1.9
  1090. log
  1091. @didn't sort correctly
  1092. @
  1093. text
  1094. @d6 1
  1095. a6 1
  1096. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.8 90/02/12 21:12:13 jhh Exp $ SPRITE (Berkeley)
  1097. d222 6
  1098. d268 5
  1099. a588 1
  1100. exit
  1101. d654 28
  1102. d683 1
  1103. d719 5
  1104. a723 1
  1105. cat /tmp/addhost.out1.$$ /tmp/addhost.out2.$$ /tmp/addhost.out3.$$ > hosts.new
  1106. d880 8
  1107. a887 3
  1108. echo "Installation of $name complete"
  1109. echo "*** Please add machine information to $root/sprite/admin/hosts"
  1110. echo "*** READ /sprite/admin/howto/addNewHost for further instructions"
  1111. @
  1112.  
  1113.  
  1114. 1.8
  1115. log
  1116. @made tftp symbolic links relative
  1117. @
  1118. text
  1119. @d6 1
  1120. a6 1
  1121. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.7 90/02/12 20:48:35 jhh Exp Locker: jhh $ SPRITE (Berkeley)
  1122. a265 1
  1123.     echo "$answer"
  1124. d412 1
  1125. a412 1
  1126.     printf("Line %d of %s: name %s already used\n", NR,  
  1127. d420 1
  1128. a420 1
  1129.     printf("Line %d of %s: id %d already used\n", NR, FILENAME, id);
  1130. d428 1
  1131. a428 1
  1132.     n = split(\$1, w);
  1133. d430 1
  1134. a430 1
  1135.         printf("Line %d of %s: id %d used in a commented-out line", NR,  
  1136. d440 2
  1137. a441 1
  1138.     printf("Line %d of %s: address %s already used\n", NR,FILENAME,"$address");
  1139. d448 1
  1140. a448 1
  1141.     printf("Line %d of %s: internet address %s already used\n", NR,  
  1142. d514 1
  1143. a514 1
  1144.     n = split(\$1, w);
  1145. d537 1
  1146. a537 1
  1147.     if (currentid > biggestid) {
  1148. d551 1
  1149. a551 1
  1150.         if (saveid[i] > id || i > etherEnd) {
  1151. d562 1
  1152. a562 1
  1153.         if (saveid[i] > id && i > inetStart && netType == "inet"){
  1154. d578 1
  1155. d756 1
  1156. a756 1
  1157.     echo "Creating $root/hosts/$name/dev/serialB"
  1158. @
  1159.  
  1160.  
  1161. 1.7
  1162. log
  1163. @adds to /sprite/admin/hosts, other new features
  1164. @
  1165. text
  1166. @d6 1
  1167. a6 1
  1168. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.6 90/01/24 16:07:49 jhh Exp Locker: jhh $ SPRITE (Berkeley)
  1169. d787 2
  1170. a788 1
  1171. $debug rm -f $root/sprite/boot/$hexInet*
  1172. d793 1
  1173. a793 2
  1174.     $debug ln -s $root/sprite/boot/sun3.md/netBoot \
  1175.         $root/sprite/boot/$hexInet
  1176. d801 1
  1177. a801 2
  1178.     $debug ln -s $root/sprite/boot/sun4.md/netBoot \
  1179.         $root/sprite/boot/$hexInet.SUN4
  1180. d809 1
  1181. a809 2
  1182.     $debug ln -s $root/sprite/boot/sun4c.md/netBoot \
  1183.         $root/sprite/boot/$hexInet.SUN4C
  1184. d817 1
  1185. @
  1186.  
  1187.  
  1188. 1.6
  1189. log
  1190. @fixed problem with quotes
  1191. @
  1192. text
  1193. @d6 1
  1194. a6 1
  1195. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.5 90/01/24 15:11:28 jhh Exp Locker: jhh $ SPRITE (Berkeley)
  1196. d20 2
  1197. d23 3
  1198. a25 4
  1199. set root=""
  1200. set sprite
  1201. set domain = `awk '/^[0-9]+/ {print substr($6, index($6,".")+1);exit;}' $root/etc/spritehosts`
  1202. #set debugFlag
  1203. d27 3
  1204. d32 2
  1205. a33 1
  1206. set tmpfile=/tmp/addhost$$
  1207. d39 1
  1208. a39 1
  1209.         case "-u":
  1210. d42 1
  1211. a42 1
  1212.             echo "-u option requires an argument"
  1213. a44 1
  1214.             unset sprite
  1215. d122 31
  1216. d192 5
  1217. d201 22
  1218. a229 1
  1219.     set onUnix = "n"
  1220. d237 27
  1221. d266 2
  1222. a267 1
  1223.     if ($answer != "") set name = $answer
  1224. d271 1
  1225. a271 1
  1226.     if ($answer != "") set machineType = $answer
  1227. d275 1
  1228. a275 1
  1229.     if ($answer != "") set netType = $answer
  1230. d279 1
  1231. a279 1
  1232.     if ($answer != "") set address = $answer
  1233. d283 1
  1234. a283 1
  1235.     if ($answer != "") set internet = $answer
  1236. d287 1
  1237. a287 1
  1238.     if ($answer != "") set domain = $answer
  1239. d291 1
  1240. a291 1
  1241.     if ($answer != "") set swapDir = $answer
  1242. d295 1
  1243. a295 1
  1244.     if ($answer != "") set spriteID = $answer
  1245. d297 9
  1246. a305 1
  1247.     echo -n "Is this script being run on Unix? (n) "
  1248. d307 3
  1249. a309 9
  1250.     if (($answer != "") && ($answer =~ [yY]*)) then
  1251.     unset sprite
  1252.     echo -n "Name of the Sprite root ($root): "
  1253.     set answer = $<
  1254.     if ($answer != "") set root = $answer
  1255.     set onUnix = "y"
  1256.     else
  1257.     set sprite
  1258.     endif
  1259. d323 9
  1260. a332 1
  1261.  
  1262. d339 2
  1263. d347 3
  1264. d351 1
  1265. a351 1
  1266.     case "ds3100"
  1267. a362 14
  1268. # Check that the given Sprite root exists
  1269. #
  1270. if (! $?sprite) then
  1271.     if (! -d $root) then
  1272.     echo "The directory $root does not exist"
  1273.     if ($?interactive) then
  1274.         goto startQuestions
  1275.     else
  1276.         goto usage
  1277.     endif
  1278.     endif
  1279. endif
  1280.  
  1281. #
  1282. d379 3
  1283. d393 3
  1284. d400 1
  1285. a400 1
  1286.     if (($answer != "") && ($answer !~ [yY]*)) goto startQuestions
  1287. d403 81
  1288. d497 1
  1289. a497 1
  1290.     type = "$machineType";
  1291. d505 6
  1292. a511 1
  1293.  
  1294. d513 13
  1295. a525 2
  1296.     save[count++] = \$0;
  1297.     next;
  1298. d528 4
  1299. a531 2
  1300.     save[count++] = \$0;
  1301.     inInet=1;
  1302. d534 5
  1303. a538 3
  1304.     if (inInet == 0) {
  1305.     for (i = 0; i < count; i++) {
  1306.         print save[i];
  1307. a539 1
  1308.     count = 0;
  1309. d541 1
  1310. a541 6
  1311.     if (assignID && \$1 > id) {
  1312.     id = \$1;
  1313.     }
  1314.     if (inInet == 0) {
  1315.     print;
  1316.     }
  1317. d545 1
  1318. a545 1
  1319.     id++;
  1320. d547 21
  1321. a567 4
  1322.     if (netType == "ether") {
  1323.     printf("%d %s %s %s %s %s %s\n", id, netType, addr, inet, type, fullName, name);
  1324.     }
  1325.     for (i = 0; i < count; i++) {
  1326. d570 3
  1327. a572 2
  1328.     if (netType == "inet") {
  1329.     printf("%d %s %s %s %s %s %s\n", id, netType, addr, inet, type, fullName, name);
  1330. d574 1
  1331. d580 1
  1332. a580 1
  1333. if ($?sprite) then
  1334. d587 1
  1335. a587 1
  1336. awk -f $tmpfile spritehosts > spritehosts.new
  1337. d596 2
  1338. a597 2
  1339. if ($?sprite) then
  1340.     $debug ci -u -m"$name added by addhost" spritehosts
  1341. d599 8
  1342. a606 2
  1343.     echo "ci -u failed ($status)"
  1344.     exit 1
  1345. d610 4
  1346. d616 28
  1347. a643 3
  1348. # I couldn't figure out a way to get the previous script to both modify
  1349. # spritehosts and return the spriteID that was assigned, so the following
  1350. # awk script looks through the new file and gets the id.
  1351. d645 11
  1352. a655 1
  1353. if ($spriteID == 0) then
  1354. d657 20
  1355. a676 1
  1356. /$name/ { print \$1; exit;}
  1357. d678 11
  1358. a688 3
  1359.     if ($?debugFlag) then
  1360.     set spriteID = `awk -f $tmpfile $root/etc/spritehosts.new`
  1361.     rm $root/etc/spritehosts.new
  1362. d690 2
  1363. a691 1
  1364.     set spriteID = `awk -f $tmpfile $root/etc/spritehosts`
  1365. a692 1
  1366.     echo "Sprite ID:        $spriteID"
  1367. d694 1
  1368. d737 1
  1369. a737 1
  1370. if ($?sprite) then
  1371. d756 1
  1372. a756 1
  1373.     if ($?sprite) then
  1374. a767 21
  1375. #
  1376. # Add the machine to /etc/hosts.equiv.
  1377. #
  1378. echo "Adding to $root/etc/hosts.equiv"
  1379. pushd $root/etc > /dev/null
  1380. if ($?sprite) then
  1381.     $debug co -l hosts.equiv
  1382.     if ($status) then
  1383.     echo "co -l failed ($status)"
  1384.     exit 1
  1385.     endif
  1386. endif
  1387. $debug echo "$fullName >> $root/etc/hosts.equiv"
  1388. if ($?sprite) then
  1389.     $debug ci -u -m"$name added by addhost" hosts.equiv
  1390.     if ($status) then
  1391.     echo "ci -u failed ($status)"
  1392.     exit 1
  1393.     endif
  1394. endif
  1395. popd > /dev/null
  1396. d785 1
  1397. a785 1
  1398. set hexInet = `echo $internet | awk -f $tmpfile`
  1399. d787 1
  1400. a787 1
  1401. $debug rm -f $root/sprite/boot/$hexInet
  1402. d823 7
  1403. a829 4
  1404. $debug mkdir $swapDir/$spriteID
  1405. if ($status) then
  1406.     echo "mkdir failed ($status)"
  1407.     exit 1
  1408. d842 1
  1409. a842 1
  1410.     rm $tmpfile
  1411. d853 1
  1412. a853 1
  1413.     echo "    [-u unixRoot] "
  1414. d856 4
  1415. @
  1416.  
  1417.  
  1418. 1.5
  1419. log
  1420. @fixed typo that caused it to assign sprite id 0
  1421. @
  1422. text
  1423. @d6 1
  1424. a6 1
  1425. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.4 90/01/18 17:55:18 jhh Exp Locker: jhh $ SPRITE (Berkeley)
  1426. d497 1
  1427. a497 1
  1428. $debug "echo $fullName >> $root/etc/hosts.equiv"
  1429. @
  1430.  
  1431.  
  1432. 1.4
  1433. log
  1434. @fixed a couple of bugs
  1435. @
  1436. text
  1437. @d6 1
  1438. a6 1
  1439. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.3 90/01/18 17:42:38 jhh Exp Locker: jhh $ SPRITE (Berkeley)
  1440. d323 1
  1441. a323 1
  1442.     if (id != -1) {
  1443. @
  1444.  
  1445.  
  1446. 1.3
  1447. log
  1448. @New! Improved! Interactive!
  1449. @
  1450. text
  1451. @d6 1
  1452. a6 1
  1453. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.2 90/01/17 17:46:40 jhh Exp Locker: jhh $ SPRITE (Berkeley)
  1454. a178 1
  1455.     echo $name
  1456. d302 1
  1457. a302 1
  1458.     echo "Is the above information correct? (y) "
  1459. @
  1460.  
  1461.  
  1462. 1.2
  1463. log
  1464. @added msg at end to read addNewHost
  1465. @
  1466. text
  1467. @d6 1
  1468. a6 1
  1469. # $Header: /sprite/src/cmds/addhost/RCS/addhost,v 1.1 90/01/16 13:20:52 jhh Exp Locker: jhh $ SPRITE (Berkeley)
  1470. d18 2
  1471. d23 4
  1472. d31 91
  1473. a121 6
  1474. while ($#argv)
  1475.     switch ($1)
  1476.     case "-u":
  1477.         shift
  1478.         if ($#argv == 0) then
  1479.         echo "-u option requires an argument"
  1480. d123 3
  1481. a125 3
  1482.         else
  1483.         unset sprite
  1484.         set root = $1
  1485. a126 6
  1486.         endif
  1487.         breaksw
  1488.     case "-i":
  1489.         shift
  1490.         if ($#argv == 0) then
  1491.         echo "-i option requires an argument"
  1492. d128 106
  1493. a233 81
  1494.         else
  1495.         set internet = $1
  1496.         shift
  1497.         endif
  1498.         breaksw
  1499.     case "-a":
  1500.         shift
  1501.         if ($#argv == 0) then
  1502.         echo "-a option requires an argument"
  1503.         else
  1504.         set address = $1
  1505.         shift
  1506.         endif
  1507.         breaksw
  1508.     case "-n"
  1509.         shift
  1510.         if ($#argv == 0) then
  1511.         echo "-n option requires an argument"
  1512.         else
  1513.         set name = $1
  1514.         shift
  1515.         endif
  1516.         breaksw
  1517.     case "-I"
  1518.         shift
  1519.         if ($#argv == 0) then
  1520.         echo "-I option requires an argument"
  1521.         else
  1522.         set spriteID = $1
  1523.         shift
  1524.         endif
  1525.         breaksw
  1526.     case "-d"
  1527.         shift
  1528.         if ($#argv == 0) then
  1529.         echo "-d option requires an argument"
  1530.         else
  1531.         set domain = $1
  1532.         shift
  1533.         endif
  1534.         breaksw
  1535.     case "-m"
  1536.         shift
  1537.         if ($#argv == 0) then
  1538.         echo "-m option requires an argument"
  1539.         else
  1540.         set machineType = $1
  1541.         shift
  1542.         endif
  1543.         breaksw
  1544.     case "-t"
  1545.         shift
  1546.         if ($#argv == 0) then
  1547.         echo "-t option requires an argument"
  1548.         else
  1549.         set netType = $1
  1550.         shift
  1551.         endif
  1552.         breaksw
  1553.     case "-s"
  1554.         shift
  1555.         if ($#argv == 0) then
  1556.         echo "-s option requires an argument"
  1557.         else
  1558.         set swapDir = $1
  1559.         shift
  1560.         endif
  1561.         breaksw
  1562.     case "-h"
  1563.     case "-help"
  1564.     case "-?"
  1565.         shift
  1566.         goto usage
  1567.         breaksw
  1568.     default:
  1569.         echo "Invalid option" $1 "to $0"
  1570.         shift
  1571.         goto usage
  1572.         breaksw
  1573.     endsw
  1574. end
  1575. d235 4
  1576. a238 23
  1577. if (! $?internet) then
  1578.     echo "-i option is required"
  1579.     goto usage
  1580. endif
  1581.  
  1582. if (! $?address) then
  1583.     echo "-a option is required"
  1584.     goto usage
  1585. endif
  1586.  
  1587. if (! $?name) then
  1588.     echo "-n option is required"
  1589.     goto usage
  1590. endif
  1591.  
  1592. if (! $?machineType) then
  1593.     echo "-m option is required"
  1594.     goto usage
  1595. endif
  1596.  
  1597. if (! $?swapDir) then
  1598.     echo "-s option is required"
  1599.     goto usage
  1600. d251 36
  1601. a286 2
  1602.     echo "Machine type must be one of (sun3, sun4, sun4c, ds3100)"
  1603.     goto usage
  1604. d289 2
  1605. d292 1
  1606. d300 1
  1607. a300 2
  1608.  
  1609. set domain = `awk '/^[0-9]+/ {print substr($6, index($6,".")+1);exit;}' $root/etc/spritehosts`
  1610. d302 4
  1611. a305 3
  1612. if ($domain == "") then
  1613.     echo "Can't determine domain from $root/etc/spritehosts. Use -d flag"
  1614.     goto usage
  1615. a307 4
  1616. set fullName=$name.$domain
  1617.  
  1618. echo "Full name:        $fullName"
  1619.  
  1620. d372 1
  1621. a372 1
  1622.     co -l spritehosts
  1623. d383 1
  1624. a383 1
  1625. mv spritehosts.new spritehosts
  1626. d388 1
  1627. a388 1
  1628.     ci -u -m"$name added by addhost" spritehosts
  1629. d405 6
  1630. a410 1
  1631.     set spriteID = `awk -f $tmpfile $root/etc/spritehosts`
  1632. d419 1
  1633. a419 1
  1634.     mkdir $root/hosts/$name.$domain
  1635. d424 1
  1636. a424 1
  1637.     chmod 777 $root/hosts/$name.$domain
  1638. d432 2
  1639. a433 2
  1640. rm -f $root/hosts/$name
  1641. ln -s $root/hosts/$name.$domain $root/hosts/$name
  1642. d441 1
  1643. a441 1
  1644.     mkdir $root/hosts/$name/dev
  1645. d446 1
  1646. a446 1
  1647.     chmod 777 $root/hosts/$name/dev
  1648. d453 1
  1649. a453 1
  1650. rm -f $root/hosts/$name/dev/syslog
  1651. d456 1
  1652. a456 1
  1653.     fsmakedev -s $spriteID -d 1 -u 0 $root/hosts/$name/dev/syslog
  1654. d475 2
  1655. a476 1
  1656.         fsmakedev -s $spriteID -d 0 -u 2 $root/hosts/$name/dev/serialB
  1657. d492 1
  1658. a492 1
  1659.     co -l hosts.equiv
  1660. d498 1
  1661. a498 1
  1662. echo $fullName >> $root/etc/hosts.equiv
  1663. d500 1
  1664. a500 1
  1665.     ci -u -m"$name added by addhost" hosts.equiv
  1666. d526 1
  1667. a526 1
  1668. rm -f $root/sprite/boot/$hexInet
  1669. d531 2
  1670. a532 1
  1671.     ln -s $root/sprite/boot/sun3.md/netBoot $root/sprite/boot/$hexInet
  1672. d540 2
  1673. a541 1
  1674.     ln -s $root/sprite/boot/sun4.md/netBoot $root/sprite/boot/$hexInet.SUN4
  1675. d549 1
  1676. a549 1
  1677.     ln -s $root/sprite/boot/sun4c.md/netBoot 
  1678. d562 1
  1679. a562 1
  1680. mkdir $swapDir/$spriteID
  1681. d569 1
  1682. a569 1
  1683.     ln -s $swapDir/$spriteID /swap/$spriteID
  1684. @
  1685.  
  1686.  
  1687. 1.1
  1688. log
  1689. @Initial revision
  1690. @
  1691. text
  1692. @d6 1
  1693. a6 1
  1694. # $Header: /sprite/src/cmds/mkscsidev/RCS/mkscsidev,v 1.2 90/01/11 15:10:01 jhh Exp $ SPRITE (Berkeley)
  1695. d442 2
  1696. a443 1
  1697. echo "Please add machine information to $root/sprite/admin/hosts"
  1698. @
  1699.